﻿using DevExpress.XtraGrid.Views.Grid;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    
    public partial class Base_ExamScoreTypeForm_List : BaseForm
    {
        ServiceBase service = new ServiceBase();
        public Base_ExamScoreTypeForm_List()
        {
            InitializeComponent();
            BindList();
        }

        private void BindList()
        {
            DataTable dt = service.GetExamScoreTypeTable(SessionerHelper.SystemYear);
           
            gridControl1.DataSource = dt;
            if (dt != null)
            {
                BindListDetail();
            }
        }

        private void BindListDetail()
        {
            DataTable dt = service.GetExamScoreTypeTable_Detail(GetSpecialityKindsNo());
            gridControl2.DataSource = dt;
        }

        private string GetSpecialityKindsNo()
        {
            string strSpecialityKindsNo_Detail = string.Empty;
            GridView rowsSelected = gridView1 as GridView;
            if (rowsSelected.Rows.Count > 0)
            {
                int[] inteurm = rowsSelected.GetSelectedRows();
                if (inteurm != null && inteurm.Length > 0)
                {
                    strSpecialityKindsNo_Detail = rowsSelected.Rows[inteurm[0]].DataRow.ItemArray[0].ToString();
                }
            }
            return strSpecialityKindsNo_Detail;
        }

        private string GetSpecialityKindsNoDetail()
        {
            string strSpecialityKindsNo_Detail = string.Empty;
            GridView rowsSelected = gridView2 as GridView;
            if (rowsSelected.Rows.Count > 0)
            {
                int[] inteurm = rowsSelected.GetSelectedRows();
                if (inteurm != null && inteurm.Length > 0)
                {
                    strSpecialityKindsNo_Detail = rowsSelected.Rows[inteurm[0]].DataRow.ItemArray[0].ToString();
                }
            }
            return strSpecialityKindsNo_Detail;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Base_ExamScoreTypeForm_Option option = new Base_ExamScoreTypeForm_Option(string.Empty);
            if (option.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                BindList();
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            string strSpecialityKindsNo_Detail = GetSpecialityKindsNo();
            if (strSpecialityKindsNo_Detail.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先选择删除项!");
            }
            else
            {
                service.DeleteExamScoreType(strSpecialityKindsNo_Detail);
                BindList();
            }
        }

        private void btnDeleteDetail_Click(object sender, EventArgs e)
        {
            string strSpecialityKindsNo_Detail = GetSpecialityKindsNoDetail();
            if (strSpecialityKindsNo_Detail.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先选择删除项!");
            }
            else
            {
                service.DeleteExamScoreType_Detail(strSpecialityKindsNo_Detail);
                BindListDetail();
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (gridView1.GetFocusedValue() != null)
            {
                string SpecialityKindsNO = GetSpecialityKindsNo();
                Base_ExamScoreTypeForm_Option option = new Base_ExamScoreTypeForm_Option(SpecialityKindsNO);
                if (option.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    BindList();
                }
            }
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            gridControl2.DataSource = null;
            BindListDetail();
        }

        private void gridView2_DoubleClick(object sender, EventArgs e)
        {
            if (gridView2.GetFocusedValue() != null)
            {
                string SpecialityKindsNO = GetSpecialityKindsNo();
                string SpecialityKindsNODetail = GetSpecialityKindsNoDetail();
                Base_ExamScoreTypeItemForm_Option option = new Base_ExamScoreTypeItemForm_Option(SpecialityKindsNO, SpecialityKindsNODetail);
                if (option.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    BindListDetail();
                }
            }
        }

        private void btnAddDetail_Click(object sender, EventArgs e)
        {
            string SpecialityKindsNO = GetSpecialityKindsNo();
            if (SpecialityKindsNO.Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先选择坪分方式!");
                return;
            }
            Base_ExamScoreTypeItemForm_Option option = new Base_ExamScoreTypeItemForm_Option(SpecialityKindsNO, string.Empty);
            if (option.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                BindListDetail();
            }

        }
    }
}
